
<script type="text/javascript">
$(document).ready(function(){
	$("select#id_sostenitore").change(function () {
		var id = "";
		id = $(this).val();
		
		if(id != '')
		{

			$.ajax({
				type: "GET",
				url: "<?php echo site_url('adozioni/contabilita/offerte/ajax_get_assistito') ?>/"+id,
				success: function(msg){
					if (msg)
					{
						
						for(var i=0;i<msg.length;i++)
						{
							$("select#id_assistito").children().remove().end().append("<option></option><option value='"+msg[i].id_assistito+"'>"+msg[i].nomecognome+"</option>");
						}
						
						
					}
				},
				dataType: 'json'
			});
		}      
	});

	if($("#id_assistito").val() != '')
	{
		$("#row_id_missione").hide();
	}
	else
	{
		$("#row_id_missione").show();
	}
	$("#id_assistito").change(function(){
		if($("#id_assistito").val() != '')
		{
			$("#row_id_missione").hide();
		}
		else
		{
			$("#row_id_missione").show();
		}
	});
    $("#form1").validate({
		rules: {
			id_sostenitore: "required",
			valore: "required",
			id_conto: "required"
		},
		messages: {
			id_sostenitore: "<?php echo __("Scegliere il sostenitore", $module) ?>",
			valore: "<?php echo __("Inserisci un valore", $module) ?>",
			id_conto: "<?php echo __("Scegliere il conto", $module) ?>"
		}
	});	
});


</script>

<h1><?php echo $title; ?></h1>
<div class="noprint">
<?php if (isset($notice) || $notice = $this->session->flashdata('notification')):?>
<p class="notice"><?php echo $notice;?></p>
<?php endif;?>


</div>

<form name="form1" id="form1" action="<?php echo site_url('adozioni/contabilita/offerte/save') ?>" method="post">
<table border="0" class="form">
  <tr>
    <th valign='top'><?php echo __("Sostenitore", $module) ?></th>
    <td class="item1">
	<select name="id_sostenitore" id="id_sostenitore" class="input-select">
	<option></option>
	<?php foreach($sostenitori as $r): ?>
	<option value="<?php echo $r['id']; ?>" <?php if($r['id'] == $row['id_sostenitore']) echo "selected"; ?>><?php echo $r['nomecognome'] ?></option>
	<?php endforeach; ?>
	</select>
	</td>
  </tr>
  <tr>
    <th valign='top'><?php echo __("Assistito", $module) ?></th>
    <td class="item1">
	<select name="id_assistito" id="id_assistito" class="input-select">
	<option></option>
	<?php foreach($assistiti as $r): ?>
	<option value="<?php echo $r['id']; ?>" <?php if($r['id'] == $row['id_assistito']) echo "selected"; ?>><?php echo $r['nomecognome'] ?></option>
	<?php endforeach; ?>
	</select>
	</td>
  </tr>
  <tr id="row_id_missione">
    <th valign='top'><?php echo __("Missione di destinazione", $module) ?></th>
    <td class="item1">
	<select name="id_missione" class="input-select">
	<?php foreach($missioni as $r): ?>
	<option value="<?php echo $r['id']; ?>" <?php if($r['id'] == $row['id_missione']) echo "selected"; ?>><?php echo $r['nome'] ?></option>
	<?php endforeach; ?>
	</select>
	

	</td>
  </tr>
  <tr>
    <th valign='top'><?php echo __("Categoria/sottocategoria", $module) ?></th>
    <td class="item1">
	<select name="c_id_s_id" class="input-select">
	<option></option>
	<?php foreach($categorie as $r): ?>
	<option value="<?php echo $r['c_id'].":".$r['s_id']; ?>" <?php if($r['c_id'].":".$r['s_id'] == $row['id_categoria'].":".$row['id_sottocategoria']) echo "selected"; ?>><?php echo $r['cat'] . ' - ' . $r['nome'] ?></option>
	<?php endforeach; ?>
	</select>
	</td>
  </tr>
 <?php /*  <tr>
    <th valign='top'><?php echo __("Tag", $module) ?></th>
    <td class="item1">
	<select name="tag" class="input-select">
	<option></option>
	<?php foreach($tags as $r): ?>
	<option value="<?php echo $r['tag']; ?>" <?php if($r['tag'] == $row['tag']) echo "selected"; ?>><?php echo $r['tag'] ?></option>
	<?php endforeach; ?>
	</select>
	</td>
  </tr> */ ?>
  <tr>
    <th valign='top'><?php echo __("Valore offerta", $module) ?></th>
    <td class="item1"><input type='text' name='valore' id='valore' value='<?php echo $row['valore']; ?>'  class="input-text"/></td>
  </tr>
  <tr>
    <th valign='top'><?php echo __("Trattenuta ufficio", $module) ?></th>
    <td class="item1"><input type='text' name='trattenuta_txt' id='trattenuta_txt' value="<?php echo $row['trattenuta_txt'] ?>" /> %</td>
  </tr>
  <tr>
    <th valign='top'><?php echo __("Data offerta", $module) ?></th>
    <td class="item1">
      <?php echo $this->off->select_data_offerta($row['data'], 'offerta'); ?></td>
	</td>
  </tr>
  <tr>
    <th valign='top'><?php echo __("Conto", $module) ?></th>
    <td class="item1">
	<select name="id_conto" id="id_conto">
	<option></option>
	<?php foreach($conti as $r): ?>
	<option value="<?php echo $r['id']; ?>" <?php if($r['id'] == $row['id_conto']) echo "selected"; ?>><?php echo $r['nome'] ?></option>
	<?php endforeach; ?>
	</select>
	
	</td>
  </tr>
  <tr>
    <th valign='top'><?php echo __("Protocollo", $module) ?></th>
     <td class="item1"><input type='text' name='protocollo' id='protocollo' value="<?php echo $row['protocollo']; ?>"  class="input-text" /></td>
  </tr>
  <tr>
    <th valign='top'><?php echo __("Note", $module) ?></th>
    <td class="item1"><textarea name='note' id='note' class="input-textarea"><?php echo $row['note']; ?></textarea></td>
  </tr>
</table>
<input type='hidden' name='redirect' value="<?php echo $redirect; ?>" />
<input type="submit" value=" <?php echo __("Salva", $module) ?> " class="input-submit" />
<input type="button" onClick="document.location = '<?php echo $redirect ?>'" value=   "<?php echo __("Annulla", $module) ?>" class="input-submit" />
<input type="hidden" name="id" value="<?php echo $row['id'] ?>" />
</form>
